#ifndef __SMOOTH_H
#define __SMOOTH_H
#include <stdint.h>

typedef struct {
    int16_t  s;
    int16_t  s_prev;
    int32_t  n;
    int32_t  y_prev;
    int32_t  y_sum;
} sfilter;
void onelv_smooth(int32_t *nsec_current, sfilter *filt);

#define KSMOOTH_COMM(input, n) ({\
    static sfilter a_filt = {n, 0, 0, 0, 0};\
    int32_t data = input;\
    onelv_smooth(&data, &a_filt);\
    data;\
})\

#define KSMOOTH_FAST(input) ({\
    static sfilter a_filt = {1, 0, 0, 0, 0};\
    int32_t data = input;\
    onelv_smooth(&data, &a_filt);\
    data;\
})\

#define KFILTER_COMM(input, n) ({\
    static uint32_t data = 0;\
    int16_t ret = 0;\
    const uint16_t f = (65536 >> n);\
    data = (uint32_t)( (uint16_t)input * f + data * (65536 - f) );\
    data = (data >> 16);\
    ret = (int16_t)data;\
    ret;\
})\



#endif


